package com.voice.core.api.model;


import lombok.Data;

import java.util.*;

@Data
public abstract class ApiHttpMessage {
    protected byte[] body;
    protected Map<String, List<String>> headers = new HashMap();

    public void addHeader(String name, String value) {
        name = name.trim().toLowerCase();
        if (this.headers.containsKey(name)) {
            this.headers.get(name).add(value);
        } else {
            List<String> values = new ArrayList();
            values.add(value == null ? "" : value.trim());
            this.headers.put(name, values);
        }
    }

    public void addHeader(Map<String, List<String>> headers) {
        if(headers!=null) this.headers.putAll(headers);
    }

    public String getFirstHeaderValue(String name) {
        return this.headers.containsKey(name) && this.headers.get(name).size() > 0 ? (String)((List)this.headers.get(name)).get(0) : null;
    }

}

